'use strict';

const Controller = require('./base');

class WinController extends Controller {

  // 中奖列表
  async list() {
    const ctx = this.ctx;
    ctx.set('Content-Type', 'application/json');
    const list = await ctx.service.win.list(ctx.query);
    this.success(list);
  }

  // 抽奖接口
  async win() {
    const ctx = this.ctx;
    const post = ctx.request.body;
    // const post = ctx.request.query;
    // PrizeType  奖品类型（一等奖，二等奖，三等奖）
    // PrizeNum    抽奖数量 100
    if (post.PrizeType == undefined && post.PrizeNum == undefined) {
      this.ctx.throw(500, '参数错误');
      return;
    }
    ctx.set('Content-Type', 'application/json');
    const created = await ctx.service.win.win(post);
    this.success(created);

  }

  // 查询用户中奖情况
  async find() {
    const ctx = this.ctx;
    const post = ctx.params;
    if (post.id == undefined) {
      this.ctx.throw(500, '参数错误');
      return;
    }
    ctx.set('Content-Type', 'application/json');  
    const created = await ctx.service.act.vote(post);
    this.success({
      msg: "投票成功"
    })
  }

}

module.exports = WinController;
